/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.manager.search;

import br.com.foxline.clinicplus.entity.Cbo;
import br.com.foxline.clinicplus.service.CboService;
import br.com.foxline.clinicplus.util.Msg;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerSearchCbo {

    @EJB
    CboService cboService;
    private Cbo searchCbo;
    private List<Cbo> cbos;
    private String ecbo;
    private String scbo;
    private Cbo editCbo;
    private Cbo showCbo;

    @PostConstruct
    public void init() {
        searchCbo = new Cbo();
        cbos = new ArrayList<Cbo>();

        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        ecbo = params.get("ecbo");
        scbo = params.get("scbo");

        if (ecbo != null) {
            this.editCbo = cboService.find(Long.parseLong(ecbo));
        } else if (scbo != null) {
            this.showCbo = cboService.find(Long.parseLong(scbo));
        }
    }

    public void pesqCBO() {
        cbos = cboService.findCBO(searchCbo);
    }

    public void update() {
        try {
            cboService.update(editCbo);
            Msg.messagemInfo("Operação Realizado com Sucesso");
        } catch (Exception erro) {
        }
    }

    public Cbo getSearchCbo() {
        return searchCbo;
    }

    public void setSearchCbo(Cbo searchCbo) {
        this.searchCbo = searchCbo;
    }

    public List<Cbo> getCbos() {
        return cbos;
    }

    public void setCbos(List<Cbo> cbos) {
        this.cbos = cbos;
    }

    public Cbo getEditCbo() {
        return editCbo;
    }

    public void setEditCbo(Cbo editCbo) {
        this.editCbo = editCbo;
    }
}
